<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%--证书使用页面--%>
<form id="mySubordinateForm">
<div class="body-main">
    <%--使用指导价--%>
    <input type="hidden" id="hangUpGuidingPrice" value="${hangUpGuidingPrice}">
        <!--使用 弹窗 start-->
        <div id="proAttached">
            <table class="add-table form-table">
                <tbody>
                <tr>
                    <th><span class="required">使用价格（元）：</span></th>
                    <td>
                        <input type="text" class="input-style" maxlength="10" name="certificatePrice" id="certificatePrice" onblur="checkSubMoney()">
                    </td>
                </tr>
                <tr>
                    <th><span class="required">使用公司：</span></th>
                    <td>
                        <input type="text" class="input-style" maxlength="200" name="affiliatedCompany" id="affiliatedCompany">
                    </td>
                </tr>
                <tr>
                    <th><span class="required">使用起始日期：</span></th>
                    <td>
                        <input type="text" class="input-style Wdate" name="affiliatedStartTime" id="affiliatedStartTime"
                               onFocus="var d4312=$dp.$('affiliatedExpireTime'); WdatePicker({onpicked:function(){d4312.focus();}, maxDate:'#F{ $dp.$D(\'affiliatedExpireTime\')}', dateFmt:'yyyy-MM-dd',minDate:'now()'})"
                        >
                    </td>
                </tr>
                <tr>
                    <th><span class="required">使用结束日期：</span></th>
                    <td>
                        <input type="text" class="input-style Wdate" name="affiliatedExpireTime" id="affiliatedExpireTime"
                               onFocus="WdatePicker({minDate:'#F{$dp.$D(\'affiliatedStartTime\')}', dateFmt:'yyyy-MM-dd'})"
                        >
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
        <!--使用 弹窗 end-->
</div>
</form>
<script type="text/javascript">
    //校验使用价格
    function checkSubMoney() {
        isFloatRangeSam('#certificatePrice',0,99999999);
    }


    function comfirmSubordinate(certificateId,certificateNo, scOrderId) {//证书ID 和  生产ID
        var certificatePrice = $('#certificatePrice').val();
        if (checkIsEmpty(certificatePrice)){
            DGG.Warning("请输入使用金额!");
            return;
        }
        var affiliatedCompany = $('#affiliatedCompany').val();
        if (checkIsEmpty(affiliatedCompany)){
            DGG.Warning("请输入使用公司!");
            return;
        }
        var affiliatedStartTime = $('#affiliatedStartTime').val();
        if (checkIsEmpty(affiliatedStartTime)){
            DGG.Warning("请输入使用起始时间!");
            return;
        }
        var affiliatedExpireTime = $('#affiliatedExpireTime').val();
        if (checkIsEmpty(affiliatedExpireTime)){
            DGG.Warning("请输入使用结束时间!");
            return;
        }
        if (!isFloatRangeSam('#certificatePrice',0,99999999)) {
            return;
        }
        var hangUpGuidingPrice = $('#hangUpGuidingPrice').val();//使用指导价
        var serializeObject = $('#mySubordinateForm').serializeObject();
        serializeObject.certificateId=certificateId;
        serializeObject.certificateNo=certificateNo;
        serializeObject.scOrderId=scOrderId;
        if (!checkIsEmpty(hangUpGuidingPrice) && parseInt(certificatePrice)<parseInt(hangUpGuidingPrice)){
            //不为空且使用价格小于指导价
            DGG.Confire('当前使用价格'+certificatePrice+'元，低于使用指导价'+hangUpGuidingPrice+'元，是否依然确认使用？','使用提示',function() {
                DGG.loading();
                $.ajax({
                    type: 'POST',
                    data: serializeObject,
                    url: sysInfo.basePath + '/zzsc/inprocess/save_certificate_subordinate.do',
                    dataType: 'JSON',
                    success: function (data) {
                        DGG.loading('close');
                        if (data.code != 0) {
                            DGG.Errors(data.msg);
                        } else {
                            DGG.Succeed("操作成功!");
                            layer.closeAll();
                            window.location.reload();
                        }
                    },
                    error: function () {
                    }
                });
            })
        } else {//指导价为空则不进行验证
            DGG.Confire('确认使用吗？','使用提示',function() {
                DGG.loading();
                $.ajax({
                    type: 'POST',
                    data: serializeObject,
                    url: sysInfo.basePath + '/zzsc/inprocess/save_certificate_subordinate.do',
                    dataType: 'JSON',
                    success: function (data) {
                        DGG.loading('close');
                        if (data.code != 0) {
                            DGG.Errors(data.msg);
                        } else {
                            DGG.Succeed("操作成功!");
                            layer.closeAll();
                            window.location.reload();
                        }
                    },
                    error: function () {
                    }
                });
            })
        }

    }
</script>

